from django.shortcuts import render

# Create your views here.
from rest_framework.generics import CreateAPIView, GenericAPIView
from rest_framework.response import Response

from users import serializers
from users.models import User
from users.serializers import UserLoginSerializer, UserLoginDataSrializer


class UserView(CreateAPIView):
    """
    用户注册
    """
    serializer_class = serializers.CreateUserSerializer


# class UserLoginView(GenericAPIView):
#     queryset = User.objects.all()
#     serializer_class = UserLoginSerializer
#
#     def post(self, request):
#         print("进入试图")
#         s = self.get_serializer(data = request.data)
#         print("ping")
#         s.is_valid(raise_exception=True)
#         print("pong")
#         print("登陆成功")
#         return Response(s.data, status=200)

class UserLoginView(GenericAPIView):
    queryset = User
    serializer_class = UserLoginSerializer

    def post(self, request):
        s = self.get_serializer(data = request.data)
        s.is_valid(raise_exception=True)
        print("登陆成功")
        return Response({"message":"ok"}, status=200)